namespace WSCeCommerce.Domain.Migrations
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<WSCeCommerce.Helpers.WSCeCommerceDBContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
        }

        protected override void Seed(WSCeCommerce.Helpers.WSCeCommerceDBContext context)
        {


            int id = 0;



            //Seed Catrgories
            Category books = new Category { CategoryId = id++, CategoryName = "books" };
            Category cds = new Category { CategoryId = id++, CategoryName = "CDs" };
            Category dvds = new Category { CategoryId = id++, CategoryName = "DVDs" };

            context.Categories.AddOrUpdate(b => b.CategoryName, books);
            context.Categories.AddOrUpdate(c => c.CategoryName, cds);
            context.Categories.AddOrUpdate(d => d.CategoryName, dvds);

            //Seed items
            id = 0;
            Item harryPotter = new Item()
            {
                ItemId = id++,
                Name = "Harry Potter",
                Categories = new List<Category> { books, cds, dvds },
                Price = 20.95f
            };

            context.Items.AddOrUpdate(h => h.Name, harryPotter);

            Item avengers = new Item()
            {
                ItemId = id++,
                Name = "Avengers",
                Price = 19.99F,
                Categories = new List<Category> { books, dvds }
            };

            context.Items.AddOrUpdate(a => a.Name, avengers);

            context.SaveChanges();


            Address addy = new Address()
            {
                AddressId = 1,
                AddressLine1 = "99 Somewhere St.",
                AddressType = AddressType.House,
                City = "Nowhere Ville",
                Country = "Canada",
                Zip = "N5I H7T"
            };

            context.Address.AddOrUpdate(a => a.AddressId, addy);

            UserAddress ua = new UserAddress()
            {
                Address = addy,
                UserId = 1
            };

            context.UserAddress.AddOrUpdate(ua);
            context.SaveChanges();

            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }


    }
}
